# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time        : 2021/10/16 08:36
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : global_equalize.py
@Version     : Version 1.0.0
@Description : TODO
@Created By  : PyCharm
"""
from skimage import exposure
from pydicom import dcmread
from DIP_experiment_5.dcm_io import bar
from DIP_experiment_5.util import contrast_show

im_path = "../experiment_fig/I1700000"
font_path = "C:/Windows/Fonts/simhei.ttf"
dcm_im = dcmread(im_path)
dcm_arr = dcm_im.pixel_array  # 2395 0
equalized_hist = exposure.equalize_hist(dcm_arr) * 2350
fig_dict = {"DICOM图像": dcm_arr, "全局直方图均衡化DICOM图像": equalized_hist}
contrast_show(fig_dict, (1, 2), font=font_path)
hist_height, hist_bins = exposure.histogram(dcm_arr, normalize=True)
equalize_hist_height, equalize_hist_bins = exposure.histogram(equalized_hist, normalize=True)
im_dict = {"DICOM图像直方图": [hist_bins, hist_height],
           "DICOM图像全局直方图均衡化后直方图": [equalize_hist_bins, equalize_hist_height]}
bar(im_dict, (1, 2), font=font_path)
